import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/utils/helper.dart';

// ignore: must_be_immutable
class AddToPlaylistDialog extends GetView<BooksController> {
  AddToPlaylistDialog({
    Key? key,
    required this.title,
    required this.message,
    required this.selected,
    required this.readingTypeFrom,
  }) : super(key: key);

  String title;
  String message;
  List<String> selected;
  String readingTypeFrom;

  @override
  Widget build(BuildContext context) {
    //Log.debug('readingType----$readingTypeFrom');
    BooksController _booksController = Get.find();
    void _addPlaylist() async {
      _booksController
          .addBooksToAudioPlaylist(selected, readingTypeFrom)
          .then((data) {
        if (data.message != null && data.status == 1000) {
          _booksController.selectedFavoriteReadingBookItemsClear();
          _booksController.selectedLibraryReadingBookItemsClear();

          showSnackMsg('Book(s) added to audio playlist successfully');
          // Get.snackbar(
          //     'Message'.tr, 'Book(s) added to audio playlist successfully'.tr,
          //     backgroundColor: Theme.of(context).primaryColor,
          //     colorText: Theme.of(context).primaryColorLight,
          //     snackPosition: SnackPosition.BOTTOM);

          Navigator.of(context).pop();
        } else {
          showSnackMsg('Error to add book(s) to audio playlist');
          // Get.snackbar(
          //     'Message'.tr, 'Error to add book(s) to audio playlist'.tr,
          //     backgroundColor: Theme.of(context).primaryColor,
          //     colorText: Theme.of(context).primaryColorLight,
          //     snackPosition: SnackPosition.BOTTOM);
        }
      });
    }

    return AlertDialog(
      title: Text(this.title),
      titleTextStyle: TextStyle(
          fontWeight: FontWeight.bold,
          letterSpacing: 1,
          color: Get.isDarkMode ? Color(0xffcccccc) : Colors.black,
          fontSize: 20),
      backgroundColor: Get.isDarkMode
          ? (Color(0xff333333))
          : Color.fromARGB(255, 234, 241, 238),
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(20))),
      content: Container(
        height: 200,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Padding(
                  padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
                  child: Text(
                    this.message,
                    style: TextStyle(fontSize: 20),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                MaterialButton(
                    color: Theme.of(context).colorScheme.secondary,
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text('Cancel'.tr)),
                MaterialButton(
                    color: Theme.of(context).colorScheme.secondary,
                    onPressed: () {
                      _addPlaylist();
                      // Future.delayed(Duration(milliseconds: 1500), (() {
                      //   String? message =
                      //       _booksController.statusMessageResult.value.message!;
                      //   if (_booksController.statusMessageResult.value.status ==
                      //       1000) {
                      //     Get.snackbar('Message'.tr, message,
                      //         backgroundColor: Theme.of(context).primaryColor,
                      //         colorText: Theme.of(context).primaryColorLight,
                      //         snackPosition: SnackPosition.BOTTOM);

                      //     Navigator.of(context).pop();
                      //   } else {
                      //     Get.snackbar('Message'.tr, message,
                      //         backgroundColor: Theme.of(context).primaryColor,
                      //         colorText: Theme.of(context).primaryColorLight,
                      //         snackPosition: SnackPosition.BOTTOM);
                      //   }
                      // }));
                    },
                    child: Text('Submit'.tr))
              ],
            ),
          ],
        ),
      ),
    );
  }
}
